#define _CRT_SECURE_NO_WARNINGS 1

#include"Stack(2).h"

void StackInit(Stack* st)
{
	assert(st);

	st->top = NULL;
	st->size = 0;
}

void StackDestory(Stack* st)
{
	assert(st);

	while (st->size > 0)
		StackPop(st);
}

void StackPush(Stack* st, StDateType x)
{
	assert(st);

	StackNode* Node = (StackNode*)malloc(sizeof(StackNode));
	if (!Node)
	{
		perror("malloc mistake");
		exit(-1);
	}
	Node->date = x;
	Node->next = NULL;

	Node->next = st->top;
	st->top = Node;
	st->size++;
}
void StackPop(Stack* st)
{
	assert(st);
	assert(st->top);

	Stack* tmp = st->top->next;
	free(st->top);

	st->top = tmp;
	st->size--;
}
StDateType StackTop(Stack* st)
{
	assert(st);
	return st->top->date;
}
bool StackEmpty(Stack* st)
{
	assert(st);
	return st->top == NULL;
}
size_t StackSize(Stack* st)
{
	return st->size;
}